# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: site-packages\pystache\parsed.py
"""
Exposes a class that represents a parsed (or compiled) template.

"""


class ParsedTemplate(object):
    """
    Represents a parsed or compiled template.
    
    An instance wraps a list of unicode strings and node objects.  A node
    object must have a `render(engine, stack)` method that accepts a
    RenderEngine instance and a ContextStack instance and returns a unicode
    string.
    
    """

    def __init__(self):
        self._parse_tree = []

    def __repr__(self):
        return repr(self._parse_tree)

    def add(self, node):
        """
        Arguments:
        
          node: a unicode string or node object instance.  See the class
            docstring for information.
        
        """
        self._parse_tree.append(node)

    def render(self, engine, context):
        """
        Returns: a string of type unicode.
        
        """

        def get_unicode(node):
            if type(node) is str:
                return node
            else:
                return node.render(engine, context)

        parts = list(map(get_unicode, self._parse_tree))
        s = ("").join(parts)
        return str(s)
